package com.dms.modules.community.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dms.modules.community.entity.CommunityFollow;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface CommunityFollowMapper extends BaseMapper<CommunityFollow> {
    
    /**
     * 检查是否互相关注
     */
    @Select("SELECT COUNT(*) FROM community_follow WHERE " +
            "user_id = #{followedUserId} AND followed_user_id = #{userId}")
    int checkFollowEachOther(@Param("userId") Long userId, @Param("followedUserId") Long followedUserId);
    
    /**
     * 分页获取关注列表
     */
    @Select("SELECT f.* FROM community_follow f " +
            "WHERE f.user_id = #{userId} " +
            "ORDER BY f.create_time DESC")
    IPage<CommunityFollow> getFollowingList(Page<?> page, @Param("userId") Long userId);
    
    /**
     * 分页获取粉丝列表
     */
    @Select("SELECT f.* FROM community_follow f " +
            "WHERE f.followed_user_id = #{userId} " +
            "ORDER BY f.create_time DESC")
    IPage<CommunityFollow> getFollowerList(Page<?> page, @Param("userId") Long userId);
} 